import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	// 来获取状态对象
	state: {
		btmActive: 0,
		navList: [
			{
				name: '首页',
				src: 'home',
				active: 0,
				icon: '../../static/icons/bottomBar/home.png',
				selectedIcon: '../../static/icons/bottomBar/home_active2.png',
			},
			{
				name: '分类',
				src: 'class',
				active: 0,
				icon: '../../static/icons/bottomBar/class.png',
				selectedIcon: "../../static/icons/bottomBar/cart_active2.png",
			},
			{
				name: '购物车',
				src: 'cart',
				active: 0,
				icon: '../../static/icons/bottomBar/cart.png',
				selectedIcon: "../../static/icons/bottomBar/cart_active2.png",
			},
			{
				name: '我的',
				src: 'user',
				active: 0,
				icon: '../../static/icons/bottomBar/user.png',
				selectedIcon: '../../static/icons/bottomBar/user_active2.png'
			}
		],
		count: 100,
		strH: '哈哈哈'
	},
	// 方法触发状态变更
	mutations: {
		btmNavNavigator (state, n) {
			state.btmActive = n
			console.log('触发了吗', state)
			state.navList.forEach((item, index) => {
				item.active = 0
				if (state.btmActive == index) {
					item.active = 1
				}
			})
		}
	}
})
store.commit('btmNavNavigator',0)
export default store